package org.bronycorps.mlptss.screen;

import org.bronycorps.mlptss.manager.CommonAssetManager;
import org.bronycorps.mlptss.manager.preferences.GameConfiguration;
import org.bronycorps.mlptss.manager.preferences.ModConfiguration.MenuConfig;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;

public abstract class AbstractMenuScreen implements Screen {

	protected GameConfiguration config;
	protected CommonAssetManager manager;
	protected MenuConfig menuConfig;
	private Skin skin;
	protected Stage stage;
	protected Table table;

	public AbstractMenuScreen() {
		super();
		this.config = GameConfiguration.getInstance();
		this.menuConfig = this.config.getCurrentMod().getMenuConfig();
		this.manager = CommonAssetManager.getInstance();

		this.stage = new Stage(LevelScreen.STAGE_WIDTH,
				LevelScreen.STAGE_HEIGHT, true);
	}

	protected void addDefaultBackground() {
		// put background image
		Texture backgroundTexture = this.manager
				.get(this.config.convertPath(this.menuConfig
						.getDefaultBackground()), Texture.class);
		backgroundTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
		Image bgImage = new Image(backgroundTexture);
		this.stage.addActor(bgImage);
	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub

	}

	protected Skin getSkin() {
		if (this.skin == null) {
			this.skin = this.manager.get(
					this.config.convertPath(this.menuConfig.getSkin()),
					Skin.class);
		}
		return this.skin;
	}

	protected Table getTable() {
		if (this.table == null) {
			this.table = new Table(getSkin());
			this.table.setFillParent(true);
			this.stage.addActor(this.table);
		}
		return this.table;
	}

	@Override
	public void hide() {
		// TODO Auto-generated method stub

	}

	@Override
	public void pause() {
		// TODO Auto-generated method stub

	}

	@Override
	public void render(float delta) {
		Gdx.gl.glClearColor(0, 0, 0, 1);
		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

		this.stage.act(delta);
		this.stage.draw();
	}

	@Override
	public void resize(int width, int height) {
		// TODO Auto-generated method stub

	}

	@Override
	public void resume() {
		// TODO Auto-generated method stub

	}

}